package com.cms.server.resolver.plugins;


import com.common.util.DateUtil;
import com.efounder.builder.base.data.EFDataSet;
import com.efounder.builder.base.data.EFRowSet;
import com.efounder.eai.data.JParamObject;
import com.efounder.form.EFFormDataModel;
import com.efounder.form.io.FormDataResolverAdapter;
import com.efounder.form.server.resolver.util.SYS_MDL_VAL;
import com.efounder.sql.JStatement;
import com.metadata.bizmodel.SYS_MODEL;
import com.persistence.FLOW_TASK_LIST;

public class CMSUpdatePSHTFormQRRQ extends FormDataResolverAdapter {

	//初始化FormDataModel
	public void finishSaveForm(JStatement stmt, EFFormDataModel model, JParamObject PO) throws Exception {
		EFDataSet                    billDataSet = model.getBillDataSet();
		EFDataSet                    itemDataSet = EFDataSet.getInstance("PSHTMX");
		String                            strSql = "";
		String                            F_GUID = billDataSet.getRowSet(0).getString(PO.GetValueByParamName(SYS_MODEL._BILL_GUID_COL_, SYS_MDL_VAL.BILL_GUID), "");
		java.util.Date                  currTime = new java.util.Date();
		EFRowSet                      itemRowSet;
		java.util.List<String>    dataSetKeyList = new java.util.ArrayList<String>();
		
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_NODE_NEXT, "N4");
		PO.SetValueByParamName(FLOW_TASK_LIST._RESR_IN_CAUSE, "submit");
		
		strSql = " update PSHTXX set F_CHDATE = '" + currTime.getTime() + "' where F_GUID = '" + F_GUID + "'";
		stmt.execute(strSql);
		
		if(billDataSet.getRowCount() > 0) {
			itemRowSet = billDataSet.getRowSet(0);
			dataSetKeyList = itemRowSet.getDataSetKeyList();
			if(dataSetKeyList.size() > 0) {
				itemDataSet = itemRowSet.getDataSet(dataSetKeyList.get(0));
				for(int i = 0; i < itemDataSet.getRowCount(); i++){
			    	itemRowSet = itemDataSet.getRowSet(i);
			    	strSql = " update PSHTMX set F_QRRQ = '" + DateUtil.date3String("yyyy-MM-dd") + "' where F_GUID = '" + F_GUID + "' and F_FLBH = '" + itemRowSet.getString("F_FLBH", "") + "'";
					stmt.execute(strSql);
				}
			}
		}
	}
}
